//
//  Ugc_Main_ScrollView_WX.m
//  ZITHER
//
//  Created by weixin on 2018/9/10.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "Ugc_Main_ScrollView_WX.h"
#import "UgcMain_VC_WX.h"
#define backHeight (Is_Iphone_X_Series ? kStatusBarHeight+10+20 : kStatusBarHeight+10+20+5)
#define bottomH (Is_Iphone_X_Series ? 80 : 45)

@implementation Ugc_Main_ScrollView_WX

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
//        self.backgroundColor = [UIColor randomColor];
        [self defaultConfiguration];
        [self setUI];
        
    }
    return self;
}


-(void)defaultConfiguration{
    self.bounces = NO;
    self.showsHorizontalScrollIndicator = NO;
    self.bounces = NO; // 默认为YES 取消设置NO
    // 当bounces属性为NO时，以下两个属性设置无效
    self.alwaysBounceHorizontal = YES; // 水平方向弹簧效果
    self.alwaysBounceVertical = YES; // 垂直方向弹簧效果
    self.decelerationRate = 0.1; // 值域 0~1 值越小减速停止的时间越短
    self.backgroundColor = [UIColor whiteColor];
    self.pagingEnabled = YES;
    self.contentSize = CGSizeMake(kScreenW*3,0);
    self.delegate = self;
}

-(void)setUI{
    [self addSubview:self.tbv1];
    [self addSubview:self.tbv2];
    [self addSubview:self.tbv3];
//    self.tbv1.backgroundColor = [UIColor randomColor];
//    self.tbv2.backgroundColor = [UIColor randomColor];

//    [self.tbv1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.bottom.equalTo(self spview]).offset(0);
//        make.width.mas_equalTo(kScreenW);
//    }];
//    [self.tbv2 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self).offset(0);
//        make.top.bottom.equalTo(self).offset(0);
//        make.width.mas_equalTo(kScreenW);
//    }];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    if (scrollView.contentOffset.x == 0) {
        [self changePage:0];
    }else if (scrollView.contentOffset.x == SCREEN_WIDTH){
        [self changePage:1];
    }else if (scrollView.contentOffset.x == SCREEN_WIDTH*2){
        [self changePage:2];
    }else{
//        [self changePage:2];
    }
}

-(void)changePage:(int)index{
    UgcMain_VC_WX *vc  = (UgcMain_VC_WX*)[self getViewController:[UgcMain_VC_WX class]];
    [vc.TitleV changeBtn:index];
    
    
}



-(Ugc_Friends_Tbv_WX *)tbv1{
    if (!_tbv1) {
        
        _tbv1 = [[Ugc_Friends_Tbv_WX alloc]initWithFrame:CGRectMake(0, 0, kScreenW,kScreenH-bottomH-TabbarHeight)];
        _tbv1.indexType = @"0";
    }
    return _tbv1;
}

-(Ugc_Friends_Tbv_WX *)tbv2{
    if (!_tbv2) {
        _tbv2 = [[Ugc_Friends_Tbv_WX alloc]initWithFrame:CGRectMake(kScreenW, 0, kScreenW, kScreenH-bottomH-TabbarHeight)];
        _tbv2.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 20)];
        _tbv2.indexType = @"1";
    }
    return _tbv2;
}

-(Ugc_Friends_Tbv_WX *)tbv3{
    if (!_tbv3) {
        _tbv3 = [[Ugc_Friends_Tbv_WX alloc]initWithFrame:CGRectMake(kScreenW*2, 0, kScreenW, kScreenH-bottomH-TabbarHeight)];
        _tbv3.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 20)];
        _tbv3.indexType = @"2";
    }
    return _tbv3;
}

@end
